package com.iwhalecloud.bss.kite.cucc.spec.impl.query;

import com.iwhalecloud.bss.kite.dataservice.api.IQueryCommonRegionService;
import com.iwhalecloud.bss.kite.dataservice.entity.CommonRegion;
import com.iwhalecloud.bss.kite.dataservice.mapper.other.CommonRegionMapper;
import com.ztesoft.bss.base.staticdata.CoreDataRegion;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Objects;

@Service("spec.queryCommonRegionService")
public class CommonRegionQueryService implements IQueryCommonRegionService {

    private final String LOC_C_0004_00 = "0";

    @Resource
    private CommonRegionMapper commonRegionMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public CommonRegion getCommonRegionByLanId(String lanId) {
        CommonRegion commonRegion = commonRegionMapper.selectCommonRegionByRegionId(lanId,
            CoreDataRegion.LOC_C_0004_20);
        if (Objects.isNull(commonRegion)) {
            commonRegion = commonRegionMapper.selectCommonRegionByRegionId(lanId, LOC_C_0004_00);
        }
        return commonRegion;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public CommonRegion getCommonRegionByRegionId(String regionId) {
        return commonRegionMapper.getCommonRegionByRegionId(regionId);
    }
}
